package com.onstar.cn.vehicle.result;

import android.content.Context;
import android.content.Intent;

import com.onstar.cn.mag.enumtype.RemoteCommandsType;

/**
 * 
* @ClassName: ResultHandler 
* @Description: 轮训service的结果由此处理发送广播
* @author 6335yz
* @date 2015年8月27日 下午8:57:12
 */
public class ResultHandler {
	
	private static ResultHandler resultHandler;
	private  Context context;
	public static ResultHandler getInstance(Context ctx) {
		if(resultHandler == null) {
			resultHandler = new  ResultHandler(ctx);
		}
		return resultHandler;
	}
	
	private ResultHandler(Context ctx) {
		this.context = ctx;
	}
	
	public void onResult(PollingResult pollingResult){
		Intent intent = new Intent();
		RemoteCommandsType commandsType = RemoteCommandsType.fromValue(pollingResult.getRequestType());
		String action = null;
		switch (commandsType) {
			case COMMANDS_LOCK_DOOR:
			case COMMANDS_UNLOCK_DOOR:
			case COMMANDS_START:
			case COMMANDS_CANCEL_START:
			case COMMANDS_ALERT:
				action = "BrocastReceiveFactory.commondsreceiver";
				break;
			case COMMANDS_LOCATION:
				action = "BrocastReceiveFactory.poireceiver";
				break;
			case COMMANDS_GEOFENCE_LOCATION:
				action = "BrocastReceiveFactory.geofencelocation";
				break;
			case COMMAND_DISABLEHOTSPOT:
			case COMMAND_ENSABLEHOTSPOT:
			case COMMAND_GETHOTSPOTINFO:
			case COMMAND_GETHOTSPOTSTATUS:
			case COMMAND_SETHOTSPOTINFO:
			case COMMAND_GETCHARGINGPROFILE:
			case COMMAND_SETCHARGINGPROFILE:
			case COMMAND_GETCOMMUTESCHEDULE:
			case COMMAND_SETCOMMUTESCHEDULE:
				action = "BrocastReceiveFactory.morereceiver";
				break;
			case COMMANDS_DIAGNOSTICS:
				action = "BrocastReceiveFactory.homereceiver";
				break;
			case COMMANDS_TBT_ROUTE:
				action = "BrocastReceiveFactory.poireceiver";
				break;
			case COMMANDS_NAV_DESTINATION:
				action = "BrocastReceiveFactory.poireceiver";
				break;
			default:
				break;
		}
		intent.setAction(action);
		intent.putExtra("pollingResult", pollingResult);
		context.sendBroadcast(intent);
		if ("BrocastReceiveFactory.commondsreceiver".equals(action)) {//针对需要公用的遥控操作单独发送广播(静态注册)RemoteCommandDialogReceiver
			intent = new Intent("BrocastReceiveFactory.·");
			intent.putExtra("pollingResult", pollingResult);
			context.sendBroadcast(intent);
		}
	}
}
